<?
include("../../../config/config.php");
$file = isset($_FILES["module"])?$_FILES['module']:"";
echo "IMPORTING FILES:<BR>";

if ($file!=""){

	#1. CHECK TO SEE IF WE HAVE THE RIGHT NAME AND STUFF
	if (strpos($file['name'],'.framework')>3){
		echo "<BR><PRE>";
	#2. move the temp file and rename it.
		move_uploaded_file($file['tmp_name'],'../../../tmp/tmp.tar.gz');
	#3. Extract the files to a temp directory
	#4. Copy the new files to their appropriate places
	#5. empty the temporary Directory
	$tmpDir = DIR_BASE."tmp";
		echo `cd $tmpDir && tar zxvf tmp.tar.gz && cp -Rf admin/* ../admin/ && cp -Rf resource/classes/* ../resource/classes/ && cp -Rf sql/* ../sql/ && rm -Rf *`;
	}
	echo "</PRE>";
	echo "<BR>Importing tables<BR>";
	$DM->loadClass("database","database");
	$nameParts = explode('.',$file['name']);
	$mysqlFile = $nameParts[0]."_".$nameParts[1].".mysql.sql";
	$mysql = implode("",file("../../../sql/$mysqlFile"));
	$db=new database();
	if ($db->connect()){
		if ($db->execute($mysql)){
			echo "Queries executed correctly - one table created";
		}else{
			echo "Oops - something wrong with the query <BR><pre>$mysql</pre><BR>";
		}
	}
	echo "<BR>";
}

?>